﻿using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security.Principal;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Security;
using KabiManagementWeb.Models;

namespace KabiManagementWeb.Controllers
{


    public class AccountController : Controller
    {
        KBManagementDataContext context = new KBManagementDataContext();
        public ActionResult Index()
        {
            return RedirectToAction("Login");
        }

        public ActionResult Login()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Login(Admin admin)
        {
            try
            {
                var ad = context.Admins.First(x => x.UserName == admin.UserName && x.Pass == admin.Pass && x.Role.F_Name == "Admin" || x.ID == 3);
                if (ad != null)
                {
                    Session["User"] = ad;
                    return RedirectToAction("Index","Home");
                }
                else {
                    return RedirectToAction("Login");
                }
            }
            catch (Exception)
            {
                
                return RedirectToAction("Login");
            }
           
        }
        public ActionResult ForgotPassWord()
        {
            return View();
        }
    }
}
